//公用样式 
require('../../assets/css/index.less');
require('../../assets/fonts/iconfont.css');

//引入weui样式
require('../../lib/weui/weui.css');
require('./course.less');
//引入工具函数 utils
const dom = require('../../utils/dom');
const https = require('../../utils/https');
const local = require('../../utils/local');

dom.ready(function() {
    let id = location.search
    console.log(id);

    https.get(`/api/train/courseDetail${id}`, function(res) {
        console.log(res);
        if (res.errno == 0) {
            console.log(res.data);
            dom.getEle('.chocolate').innerHTML = res.data.name
            dom.getEle('video').src = 'http://fitness.h5.itsource.cn:3701' + res.data.fragments[0].videoUrl
            dom.getEle('#desc').innerHTML = res.data.desc
            dom.getEle('#calorie').innerHTML = res.data.calorie
            dom.getEle('#time').innerHTML = res.data.time

            let flag = true
            dom.addEvent('#playBtn', function() {
                if (flag) {
                    dom.getEle('video').play()
                    this.className = 'iconfont icon-zanting1'
                } else {
                    dom.getEle('video').pause()
                    this.className = "iconfont icon-youjiantou"
                }
                flag = !flag
            })
            dom.getEle('#starBtn').setAttribute('data-id', res.data.courseId)
            local.set('videoS', res.data.fragments)

        }
    })
    let userDate = local.get('userData')
    dom.getEle('#userName').innerHTML = userDate.nickName
    dom.getEle('#pic').src = 'http://fitness.h5.itsource.cn:3701' + userDate.imgUrl

    //    跳转下一个页面
    dom.addEvent('#starBtn', function(e) {
        let id = e.target.dataset['id']
        location.href = 'player.html?id=' + id
    })
    dom.addEvent('#backBtn', function() {
        location.href = 'train.html'
    })

})